<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateChangeGeneralDataTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        // 迎新基础数据表
        Schema::create('basic_new_arrivals', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->unique()->comment('迎新编码');
            $table->string('enrollment_year')->comment('招生年份');
            $table->string('enrollment_term')->comment('招生学期');
            $table->integer('enrollment_serial')->comment('招生序号');
            $table->boolean('isOn')->default(false)->comment('当前是否启动');
            $table->softDeletes();
            $table->timestamps();

            $table->foreign('enrollment_term')->references('code')->on('basic_terms')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 新生基础数据表
        Schema::create('basic_new_students', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
//            $table->string('code')->unique()->comment('学号');
            $table->string('arrival_code')->comment('迎新代码');
            $table->string('enrollment_numbering')->comment('招生编号');
            $table->string('exam_code')->unique()->comment('考试号');
            $table->string('name')->comment('姓名');
            $table->integer('sex')->nullable()->comment('性别  1:男 2:女');

            $table->string('avatar')->nullable()->comment('头像');
            $table->string('mobile',16)->nullable()->comment('联系电话');
            $table->string('address')->nullable()->comment('家庭住址');
            $table->string('card_type')->nullable()->comment('证件类型');
            $table->string('card_number')->nullable()->comment('证件号');
            $table->string('birthday')->nullable()->comment('出生日期');

            $table->string('original_type')->nullable()->comment('生源类别');
            $table->string('admission_property')->nullable()->comment('录取性质');
            $table->string('enrollment_type')->nullable()->comment('招生类型');
            $table->string('exam_province')->nullable()->comment('报考省市/生源省市');
            $table->string('exam_area')->nullable()->comment('报考区县');
            $table->string('graduated_school')->nullable()->comment('毕业学校');
            $table->string('school_type')->nullable()->comment('学校类别');


            $table->float('score')->nullable()->comment('成绩');
            $table->string('political_status')->nullable()->comment('政治面貌');

            $table->integer('height')->nullable()->comment('身高');
            $table->integer('weight')->nullable()->comment('体重');
            $table->string('body_type')->nullable()->comment('体型');
            $table->string('physical_fitness')->nullable()->comment('身体素质');
            $table->string('psychological_quality')->nullable()->comment('心理素质');
            $table->string('medical_history')->nullable()->comment('病史');
            $table->string('blood_type')->nullable()->comment('血型');
            $table->string('ill_remark')->nullable()->comment('病史备注说名');


            $table->string('enrollment_category')->nullable()->comment('招生类别');
            $table->string('enrollment_code')->nullable()->comment('招生代码');
            $table->string('enrollment_directory')->nullable()->comment('招生目录');
            $table->string('major_directory_code')->nullable()->comment('专业目录代码');
            $table->string('academic_category')->nullable()->comment('学制类别');
            $table->string('read_year')->nullable()->comment('就读年限');
            $table->string('school_mode')->nullable()->comment('办学模式');


            $table->string('ethnic')->nullable()->comment('民族');
            $table->string('household')->nullable()->comment('户口性质');
            $table->string('support_type')->nullable()->comment('资助类型');

            $table->string('enrollment_teacher')->nullable()->comment('招生老师');
            $table->string('remark')->nullable()->comment('备注');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 监护人基础数据表
        Schema::create('basic_custodians', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');

            $table->string('exam_code')->comment('考试号');
            $table->string('custodian_title')->comment('监护人称谓');
            $table->string('custodian_name')->comment('监护人姓名');
            $table->string('custodian_mobile',16)->comment('监护人手机号码');

            $table->softDeletes();
            $table->timestamps();

        });


        // 志愿基础数据表
        Schema::create('basic_majors', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('专业代码');
            $table->string('name')->comment('专业名称');
            $table->string('parent_code')->comment('父类专业名称');
            $table->integer('min_number')->nullable()->comment('至少填报志愿数');
            $table->integer('max_number')->nullable()->comment('至多填报志愿数');
            $table->integer('count')->nullable()->comment('专业招生计划人数');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();
            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        // 生活用品基础数据表
        Schema::create('basic_daily_uses', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('生活用品代码');
            $table->string('name')->comment('生活用品名称');
            $table->string('remark')->nullable()->comment('用品备注');
            $table->integer('count')->comment('人均用品数量');
            $table->string('unit')->comment('数量单位');
            $table->integer('sex_limit')->default(1)->comment('性别限制  1:男女不限  2：男生领用  3: 女生领用');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 新生教材基础数据表
        Schema::create('basic_textbooks', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('教辅教材代码');
            $table->string('name')->comment('教辅教材名称');
            $table->string('remark')->nullable()->comment('用品备注');
            $table->integer('count')->comment('人均派发数量');
            $table->string('unit')->comment('数量单位');
            $table->json('majors')->nullable()->comment('领用专业，可多选');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 校服基础数据表
        Schema::create('basic_clothes', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('校服代码');
            $table->string('name')->comment('校服名称');
            $table->string('picture')->nullable()->comment('校服图片');
            $table->string('remark')->nullable()->comment('校服备注');
            $table->integer('count')->comment('人均校服数量');
            $table->string('unit')->comment('数量单位');
            $table->integer('sex_limit')->default(1)->comment('性别限制  1:男女不限  2：男生领用  3: 女生领用');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });

        // 校服尺寸基础数据表
        Schema::create('basic_clothe_size', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('尺寸代码');
            $table->string('name')->comment('尺寸名称');
            $table->string('cloth_code')->comment('校服代码');
            $table->integer('height_low')->comment('适合最低身高');
            $table->integer('height_high')->comment('适合最高身高');
            $table->integer('size')->nullable()->comment('尺寸大小');
            $table->integer('cloth_length')->nullable()->comment('衣长');
            $table->integer('bust')->nullable()->comment('胸围');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 费用清单基础数据表
        Schema::create('basic_pays', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('费用项目代码');
            $table->string('name')->comment('费用名称');
            $table->string('remark')->nullable()->comment('备注');
            $table->decimal('amount')->comment('金额');
            $table->string('unit')->comment('费用单位');
            $table->string('type')->nullable()->comment('减免学生类型');
            $table->decimal('sub_amount')->nullable()->comment('减免金额');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 迎新日程基础数据表
        Schema::create('basic_timetables', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('迎新日程代码');
            $table->string('name')->comment('日程活动名称');
            $table->string('time')->comment('日期');
            $table->text('detail')->comment('具体时间要求');
            $table->string('address')->comment('地点');
            $table->string('reception_person')->nullable()->comment('接待单位或人员');
            $table->string('attention')->nullable()->comment('注意事项');
            $table->json('relate_information')->nullable()->comment('关联信息');
            $table->integer('show_order')->comment('显示顺序');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        //现场报道流程
        Schema::create('basic_report_processes', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('现场报到任务代码');
            $table->string('name')->comment('现场报到任务名称');
            $table->text('detail')->comment('具体时间要求');
            $table->string('address')->comment('地点');
            $table->string('reception_person')->nullable()->comment('接待单位或人员');
            $table->string('handle_procedures')->nullable()->comment('办理手续');
            $table->string('remark')->nullable()->comment('备注');
            $table->json('relate_information')->nullable()->comment('关联信息');
            $table->string('arrival_code')->comment('迎新代码');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('arrival_code')->references('code')->on('basic_new_arrivals')
                ->onDelete('restrict')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('basic_new_arrivals');
        Schema::dropIfExists('basic_new_students');
        Schema::dropIfExists('basic_majors');
        Schema::dropIfExists('basic_daily_uses');
        Schema::dropIfExists('basic_textbooks');
        Schema::dropIfExists('basic_clothes');
        Schema::dropIfExists('basic_clothe_size');
        Schema::dropIfExists('basic_pays');
        Schema::dropIfExists('basic_timetables');
        Schema::dropIfExists('basic_report_processes');
    }
}
